﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity.Admin;

namespace Web.Areas.Admin.Controllers
{ 
    public class NotificationController : Controller
    {
        private DBEntities db = new DBEntities();

        //
        // GET: /Admin/Notification/

        public ViewResult Index()
        {
            var notifications = db.Notifications.Include(n => n.User);
            return View(notifications.ToList());
        }

        //
        // GET: /Admin/Notification/Details/5

        public ViewResult Details(string id)
        {
            Notification notification = db.Notifications.Find(id);
            return View(notification);
        }

        //
        // GET: /Admin/Notification/Create

        public ActionResult Create()
        {
            ViewBag.User_ID = new SelectList(db.Users, "ID", "UserName");
            return View();
        } 

        //
        // POST: /Admin/Notification/Create

        [HttpPost]
        public ActionResult Create(Notification notification)
        {
            if (ModelState.IsValid)
            {
                db.Notifications.Add(notification);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.User_ID = new SelectList(db.Users, "ID", "UserName", notification.User_ID);
            return View(notification);
        }
        
        //
        // GET: /Admin/Notification/Edit/5
 
        public ActionResult Edit(string id)
        {
            Notification notification = db.Notifications.Find(id);
            ViewBag.User_ID = new SelectList(db.Users, "ID", "UserName", notification.User_ID);
            return View(notification);
        }

        //
        // POST: /Admin/Notification/Edit/5

        [HttpPost]
        public ActionResult Edit(Notification notification)
        {
            if (ModelState.IsValid)
            {
                db.Entry(notification).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.User_ID = new SelectList(db.Users, "ID", "UserName", notification.User_ID);
            return View(notification);
        }

        //
        // GET: /Admin/Notification/Delete/5
 
        public ActionResult Delete(string id)
        {
            Notification notification = db.Notifications.Find(id);
            return View(notification);
        }

        //
        // POST: /Admin/Notification/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {            
            Notification notification = db.Notifications.Find(id);
            db.Notifications.Remove(notification);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}